package cn.tedu.mvcboottest.common.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Getter
@Setter
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    @ApiModelProperty(value = "状态码")
    private Integer state;
    @ApiModelProperty(value = "提示信息")
    private String message;
    @ApiModelProperty(value = "返回信息")
    private Object data;

    public JsonResult(StatuCode statuCode){
        this.state=statuCode.getState();
        this.message= statuCode.getMessage();
    }
    public JsonResult(StatuCode statuCode,Object data){
        this.state=statuCode.getState();
        this.message=statuCode.getMessage();
        this.data=data;
    }

    public static JsonResult ok(Object data){
        return new JsonResult(StatuCode.OPERATION_SUCCESS,data);
    }

    public static JsonResult ok(){
        return ok(null);
    }

    public static JsonResult fail(Object data){
        return new JsonResult(StatuCode.OPERATION_FAILED,data);
    }
}
